<?php
if (isset($_POST['ph']) && isset($_POST['ncid'])) {
   $phone=addslashes(trim($_POST['ph']));
   $ncid=addslashes(trim($_POST['ncid']));
   $openid=addslashes(trim($_POST['op']));
   $testUrl='https://nc-api-test.51wom.com/api/customerUserMountainClimbing/check';
   $getUrl=$testUrl.'?ncid='.$ncid.'&phone='.$phone;
   $getData=json_decode(file_get_contents($getUrl), true);
   if (isset($getData['data']) && 1 == $getData['data'] ){ 
      include '../../c/config.php';
      $mysqli = new mysqli($dbhost, $dbuser, $dbpwd, $dbName);
      $queryG=$mysqli->query("select id from zuansu_user where openid='".$openid."'  limit 0, 1");
      if($queryG->num_rows>0){
         
      }else{
         $mysqli->query("insert into zuansu_user(openid,phone,ncid,sutype,createtime) values('".$openid."','".$phone."','".$ncid."','".$getData['data'] ."','".date("Y-m-d H:i:s")."') ");
      }
      $uid='';
      $queryG=$mysqli->query("select id from zuansu_user where openid='".$openid."'  limit 0, 1");
      if($queryG->num_rows>0){
         $getD=$queryG->fetch_assoc();
         $uid=$getD['id'];
      }

      if (!empty($uid) && !empty($openid)) {  
         $sql="select id from `zsu_user_log` where openid='".$openid."'  limit 0,1 ";
         $query = $mysqli->query($sql);
         if($query->num_rows>0){

         }else{
         $sql="INSERT INTO `zsu_user_log` (`id`, `openid`, `zslink`,`ji`, `createtime`) VALUES (NULL, '".$openid."', '".$uid."','1', '".date("Y-m-d H:i:s")."')";
         $mysqli->query($sql);
         }
      }


      $mysqli->close();
   	  echo json_encode(array('s' => 'y','link'=>'http://climb-game.51wom.com/?zslink='.$uid));
   }else{
       echo json_encode(array('s' => 'n'));
   }
 
}else{
   echo json_encode(array('s' => 'n','e'=>'lost'));
}



/**
测试环境
手机号：13681737112
NCID：81737112
身份：NC
*/

